package com.ling.payservice.service.Impl;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AccPayeeInfo;
import com.alipay.api.domain.AlipayFundTransToaccountTransferModel;
import com.alipay.api.domain.AlipayFundTransUniTransferModel;
import com.alipay.api.domain.Participant;
import com.alipay.api.request.AlipayFundTransToaccountTransferRequest;
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
import com.ling.payservice.constant.AliPayConfig;
import com.ling.payservice.service.AliTransferToAccountService;
import org.springframework.stereotype.Service;

import java.util.Random;

@Service
public class AliTransferToAccountServiceImpl implements AliTransferToAccountService{


    @Override
    public Boolean transferToAccount() throws AlipayApiException {
                AliPayConfig aliPayConfig = new AliPayConfig();
        AlipayClient alipayClient = new DefaultAlipayClient(aliPayConfig.getGateway_url(),aliPayConfig.getAppid(),
                aliPayConfig.getApp_private_key(),"json","UTF-8",aliPayConfig.getAli_public_key(),"RSA2");
        AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
        AlipayFundTransUniTransferModel transferModel = new AlipayFundTransUniTransferModel();

        transferModel.setTransAmount("10.00");
        String outTradeNo = System.currentTimeMillis()+(new Random().nextInt())+"";
        transferModel.setOutBizNo(outTradeNo);
        transferModel.setProductCode("TRANS_ACCOUNT_NO_PWD");
        Participant participant = new Participant();
        participant.setIdentity("18702890150");
        participant.setIdentityType("ALIPAY_LOGON_ID");
        participant.setName("梁玲");
        transferModel.setPayeeInfo(participant);
        transferModel.setRemark("汤圆的沙箱单笔转账demo");
        transferModel.setBizScene("DIRECT_TRANSFER");
        request.setBizModel(transferModel);
        AlipayFundTransUniTransferResponse response =alipayClient.execute(request);
        System.out.println(response.getBody());
        return null;
    }
}
